package com.lonely.deliver.enums;

import cn.hutool.core.util.StrUtil;
import com.lonely.common.exception.BusinessException;
import lombok.Getter;

/**
 * @author : 黄志标
 * @date: 2025/8/19 14:51
 * @description: 订单发货单相关枚举
 */
public class OrderDeliverEnum {

    /**
     * 发货单状态枚举
     */
    @Getter
    public enum StatusEnum {
        TO_BE_PACKED(1, "待打包"),
        PACKED(2, "已打包"),
        URGE_DELIVERY(3, "催发货"),
        PENDING_RECEIPT(4, "待收货"),
        RECEIVED(5, "已收货"),
        PENDING_RETURN(6, "待退货"),
        ALREADY_WAREHOUSED(7, "已入仓");

        /**
         * 状态值
         */
        private final int status;

        /**
         * 状态名称
         */
        private final String statusStr;

        StatusEnum(int status, String statusStr) {
            this.status = status;
            this.statusStr = statusStr;
        }
    }

    /**
     * 发货类型枚举
     */
    @Getter
    public enum ReasonEnum {

        /**
         * 首次发货
         */
        FIRST_SHIPMENT(1, "首次发货"),

        /**
         * 次品发货
         */
        DEFECTIVE_PRODUCTS_SHIPMENT(2, "次品发货"),

        /**
         * 全退发货
         */
        FULL_RETURN_SHIPMENT(3, "全退发货"),

        /**
         * 退货发货
         */
        RETURN_AND_SHIPMENT(4, "退货发货");

        /**
         * 发货类型
         */
        private final int reason;

        /**
         * 发货类型名称
         */
        private final String reasonStr;

        ReasonEnum(int reason, String reasonStr) {
            this.reason = reason;
            this.reasonStr = reasonStr;
        }

        /**
         * 根据发货类型名称获取发货类型
         *
         * @param reasonStr
         * @return
         */
        public static Integer getReason(String reasonStr) {

            if(StrUtil.isBlank(reasonStr)){
                return null;
            }

            for (ReasonEnum reasonEnum : ReasonEnum.values()) {
                if (reasonEnum.getReasonStr().equals(reasonStr)) {
                    return reasonEnum.getReason();
                }
            }
            throw new BusinessException(String.format("发货类型:%s对应枚举不存在", reasonStr));
        }
    }

}
